package com.wxdc.nmgyt.nmgytwydc.activity.common;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.just.agentwebX5.AgentWebX5;
import com.wxdc.nmgyt.nmgytwydc.model.CbYfInfoBean;

/**
 * Created by Administrator on 2018/10/24.
 */

public class CbYfInfoCommon {
    private static volatile  CbYfInfoCommon instance;
    private static Context mContext;
    private static AgentWebX5 mWebX5;
    private static  Gson mGson;
    private CbYfInfoCommon(){}
    public static CbYfInfoCommon getInstance(Context context,AgentWebX5 agentWebX5) {
        if (instance == null) {
            synchronized (YdInfoCommon.class) {
                if (instance == null) {
                    mContext = context;
                    mWebX5 = agentWebX5;
                    mGson = new Gson();
                    instance = new CbYfInfoCommon();
                }
            }
        }
        return instance;
    }

    /**
     * 利用本地数据填充网页
     * @param cbYfInfoBean
     */
    public  void loadHtmlLocalData(CbYfInfoBean cbYfInfoBean){
        mWebX5.getJsEntraceAccess().quickCallJs("callJsLocalExistCbYfInfo", mGson.toJson(cbYfInfoBean));
        if (cbYfInfoBean.getIMGPATH() != null) {
            String[] s = cbYfInfoBean.getIMGPATH().split(",");
            Log.i("TAG", "cbfzyf------webViewInitComplete: --------" + s.length);
            for (int i = 0; i < s.length; i++) {
                s[i] = s[i] + "?" + Math.random();
                Log.i("TAG", "cbfzyf-------webViewInitComplete: --------" + s[i]);
            }
            mWebX5.getJsEntraceAccess().quickCallJs("callJsShowPic", mGson.toJson(s));
        }
    }
}
